﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using MotionCS.Config;
using MotionCS.Helper;

namespace MotionCS.CameraVision
{
    public class VisionDevice : SingleObjectBase<VisionDevice>
    {       
        /// <summary>
        /// 实例化相机
        /// </summary>
        /// <param name="type"></param>
        /// <param name="strName"></param>
        /// <returns></returns>
        public ICamera GetCamera(CameraTypeE type, string strName = "")
        {
            List<ICamera> cameras = new List<ICamera>();

            switch (type)
            {
                case CameraTypeE.Dahua:
                    cameras = DahvisionGrab.SearchDeviceList();
                    break;
                default:
                    cameras = HikvisionGrab.SearchDeviceList();
                    break;
            }

            if (string.IsNullOrEmpty(strName))
            {
                return cameras.Count == 0 ? null : cameras[0];
            }
            else
            {
                return cameras.Find(p => p.Info.strName.Contains(strName));
            }
        }
    }
}
